function pageReady() {
    if($("#gg").val()==2){
        $("#path").show();
    }
    if($("#gg").val()==3){
        $("#type").show();
    }
    $("#articleType option[value='"+$("#articleTypes").val()+"']").attr("selected",true);
    //返回
    $("#goBack").click(function () {
        layuiFunciton.closeOpen();
    });

    //判断是否存在附件
    var listUrl = $("#articleUrl").val();
    var i=0;
    for(;listUrl.indexOf("tu")>=0;){
        var str = listUrl.substring(1,listUrl.indexOf(")"));
        if(str!=undefined && str != ''){
            var list = str.split(";");
            $("#show").append("<span id='s"+i+"'> <i class='layui-icon'  style='color:#3a6f9f;'>&#xe64c;</i> <a href='"+list[0]+"'><span>"+list[1]+"</span></a><a href='javascript:void(0)' onclick='delFu(&apos;s"+i+"&apos;,&apos;"+str+"&apos;);' style='color:#3a6f9f;padding: 0 5px;'>删除</a>&nbsp;&nbsp;&nbsp;&nbsp;</span>")
            listUrl = listUrl.substring(listUrl.indexOf(")")+1,listUrl.length);
        }else{
            return ;
        }
        i++;
    }

    //添加附件
    $("#url").click(function () {
        $('#upload').click();
    });

    $("#upload").change(function () {
        var fileObj = document.getElementById("upload").files[0]; // js 获取文件对象
        var formFile = new FormData();
        formFile.append("file", fileObj); //加入文件对象
        formFile.append("isShrink",  false); //加入文件对象
        formFile.append("type", 'NEWS_INFO_IMG'); //加入文件对象
        formFile.append("code", 'POLICY_NEWS_IMG'); //加入文件对象
        var data = formFile;
        $.ajax({
            url: layuiFunciton.URL + "/file/fileUpload/uploadFile",
            data: data,
            type: "Post",
            dataType: "json",
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (result) {
                $.each(result.data, function (index, file) {
                    $("#articleUrl").val("("+file.relativePath+";"+file.originalName+")"+$("#articleUrl").val());
                    $("#show").append("<span id='"+file.id+"'> <i class='layui-icon'  style='color:#3a6f9f;'>&#xe64c;</i><span>"+file.originalName+"</span><a href='javascript:void(0)' onclick='delFu(&apos;"+file.id+"&apos;,&apos;"+file.relativePath+";"+file.originalName+"&apos;);' style='color:#3a6f9f;padding: 0 5px;'>删除</a>&nbsp;&nbsp;&nbsp;&nbsp;</span>")
                    $(".allUrl").append(file.filePath+";");
                });
            }
        })
    })

	//判断是否存在图片
	if($("#img").val() != null && $("#img").val() !=""){
        $("#previewImg").attr("src",$("#img").val());
        $("#dele").show();
    }

	 layui.use(['laydate', 'upload', 'layedit','layer','form'],function() {
		var laydate = layui.laydate;
		var upload = layui.upload;
		var layedit = layui.layedit;
		var form 	= layui.form;
		 var layer = parent.layer === undefined ? layui.layer : top.layer;
		 //加载时间控件
		laydate.render({
			elem: '#publishTime' //指定元素
		});
		//普通图片上传
		var uploadInst = upload.render({
			elem: '#text1',
			url:  layuiFunciton.URL + '/file/fileUpload/uploadFile?isShrink=false&type=NEWS_INFO_IMG&code=NEWS_INFO_IMG',
			size:1024,
			before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					console.log(result)
					$('#previewImg').attr('src', result); //图片链接（base64）
				});
			},
			done: function(res){
				//如果上传失败
				if(res.code > 0){
					return layer.msg('上传失败');
				}
				//上传成功
                $("#articlePicture").val(res.data[0].relativePath);
				$("#fileInfoId").val(res.data[0].id);
				$("#img").attr('value','1');
				$("#dele").show();
			},error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInst.upload();
				});
			}
		});
		 /**
		 * 删除预览图片
		 */
		$("#dele").click(function() {
			$("#dele").hide();
			$("#img").val("");
			$("#fileInfoId").val("");
			$("#previewImg").attr("src","/public/images/img-def.png");
		});
			
			//实例化编辑器
			//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
			UE.delEditor('articleContent');
			var ue = UE.getEditor('articleContent');
			ue.addListener( "selectionchange", function () {  //编辑器的实时处理事件
				$("#articleContent-has-error").removeClass('has-error');
				$("#articleContent-error").remove();
			});
			
			//表单提交(直接发布)
			layuiFunciton.formSubmit({
				filterName:'addSubmit',  //监听提交按钮   例如：filterName： updateSubmit   <button class="layui-btn" lay-submit  lay-filter="updateSubmit" >保存</button>
				url:  layuiFunciton.URL + '/article/update?publishState=4',//提交路径
				formId:'editForm',//form表单ID
				success:function (data) {
					layuiFunciton.closeOpen();
				}
			});
			
			//表单提交(保存草稿)
			layuiFunciton.formSubmit({
				filterName:'btnSubmitFormDraft',  //监听提交按钮   例如：filterName： updateSubmit   <button class="layui-btn" lay-submit  lay-filter="updateSubmit" >保存</button>
				url:  layuiFunciton.URL + '/article/update?publishState=0',//提交路径
				formId:'editForm',//form表单ID
				success:function (data) {
					layuiFunciton.closeOpen();
				}
			});
			
			//表单提交(保存后预览)
			layuiFunciton.formSubmit({
				filterName:'btnSubmitForm1',  //监听提交按钮   例如：filterName： updateSubmit   <button class="layui-btn" lay-submit  lay-filter="updateSubmit" >保存</button>
				url:  layuiFunciton.URL + '/article/update?publishState=4',//提交路径
				formId:'editForm',//form表单ID
				success:function (data) {
					layuiFunciton.closeOpen();
					var newTab =window.open("about:blank");
					newTab.location.href = "http://localhost:8081/views/projDetail.html?id="+$("#id").val()
				}
			});
			
			//一级下拉框改变时(监听事件)
			form.on('select(change)',function(data){
				var selectHtml1='';
				$.ajax({
					type: "post",
					url:  layuiFunciton.URL + '/column/selectParenById?parentId='+data.value,
					cache:false,
					async:false,
					dataType: "json",
					success: function(data){
						var array = eval(data.data);
						selectHtml1+=' <option selected value="">请选择...</option>';
						for(var i =0;i<array.length;i++){
								selectHtml1+=' <option value="'+array[i].id+'">'+array[i].columnTitle+'</option>';
						}
						$("#columnId").html(selectHtml1);
						form.render('select');
					}
				});
			})
			
		});
		
		 //根据二级查询父级ID
	var parentId 	= "";
    var selectHtml2	= '';
	$.ajax({
		type: "get",
		url:  layuiFunciton.URL + '/column/selectByPrimaryKey?id='+$("#gg").val(),
		cache:false,
		async:false,
		dataType: "json",
		success: function(data){
			parentId = data.data.parentId;

		}
	});
	//获取一级菜单进度
    $.ajax({
        type: "get",
        url:  layuiFunciton.URL + '/column/selectParenById?parentId=28',
        cache:false,
        async:false,
        dataType: "json",
        success: function(data){
            var array = eval(data.data);
            if(parentId==28){
                selectHtml2+=' <option selected value="28">栏目管理</option>';
            }else{
                for(var i =0;i<array.length;i++){
                    if(array[i].id==parentId){
                        selectHtml2+=' <option selected value="'+array[i].id+'">'+array[i].columnTitle+'</option>';
                    }else{
                        selectHtml2+=' <option value="'+array[i].id+'">'+array[i].columnTitle+'</option>';
                    }

                }
			}

        }
    });
    $("#columnIds").append(selectHtml2);



    //二级下拉框
    var selectHtml='';
    $.ajax({
        type: "get",
        url:  layuiFunciton.URL + '/column/selectParenById?parentId='+parentId,
        cache:false,
        async:false,
        dataType: "json",
        success: function(data){
           // console.log(data)
            var array = eval(data.data);
            for(var i =0;i<array.length;i++){
                if(array[i].id==$("#gg").val()){
                    selectHtml+=' <option selected value="'+array[i].id+'">'+array[i].columnTitle+'</option>';
                }else{
                    selectHtml+=' <option value="'+array[i].id+'">'+array[i].columnTitle+'</option>';
                }

            }
        }
    });
    $("#columnId").append(selectHtml);
}

//删除附件
function delFu(id,path){
    var str = $("#articleUrl").val();
    if(str.indexOf("(http://caiyuankeji.vicp.io:7773/tmpdir"+path+")")>=0)
        str = str.replace("(http://caiyuankeji.vicp.io:7773/tmpdir"+path+")","");
    if(str.indexOf("("+path+")")>=0)
        str = str.replace("("+path+")","");
    $("#articleUrl").val(str);
    document.getElementById(id).innerHTML=" ";
}
